local wangshi = fk.CreateSkill {
  name = "lingling__wangshi",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable{
  ["lingling__wangshi"] = "王师",
  [":lingling__wangshi"] = "锁定技，出牌阶段开始时，你视为使用任意一张目标为其他角色的锦囊牌，每局每种牌名限一次。",

  ["#lingling__wangshi-invoke"] = "王师：请视为使用一张普通锦囊牌",
  ["@$lingling__wangshi"] = "王师",
}

wangshi:addEffect(fk.EventPhaseStart, {
  anim_type = "special",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(wangshi.name) and player.phase == Player.Play and
      #player:getViewAsCardNames(wangshi.name, Fk:getAllCardNames("t"), nil, player:getTableMark("@$lingling__wangshi")) > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local all_names = Fk:getAllCardNames("t")
    for i = #all_names, 1, -1 do
      if table.contains(player:getTableMark("@$lingling__wangshi"), Fk:cloneCard(all_names[i]).name) then
        table.removeOne(all_names, i)
      end
    end
    local use = room:askToUseVirtualCard(player, {
      name = player:getViewAsCardNames(wangshi.name, Fk:getAllCardNames("t"), nil, player:getTableMark("@$lingling__wangshi")),
      skill_name = wangshi.name,
      prompt = "#lingling__wangshi-invoke",
      cancelable = false,
    })
    if use and not player.dead then
      room:addTableMark(player, "@$lingling__wangshi", use.card.name)
    end
  end,
})

wangshi:addEffect("prohibit", {
  is_prohibited = function (self, from, to, card)
    return card and to and table.contains(card.skillNames, wangshi.name) and to == from
  end,
})

wangshi:addLoseEffect(function (self, player, is_death)
  player.room:setPlayerMark(player, "@$lingling__wangshi", 0)
end)

return wangshi
